
$(function() {	
	Tip.emp('员工');
});

var BusinessMy = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},			
			
			"添加": function() {				
				if (!confirm("确认是否添加？")) {
					return false;
				}				
	
				var form = $("#form_add")[0];
	
				var body = { };
				body.emp = form.emp.value;
				body.date = form.date.value;
				body.expect = form.expect.value;
				body.type = form.type.value;
				body.name = form.name.value;
				body.opinion1 = form.opinion1.value;
				body.opinion2 = form.opinion2.value;
				
				// body.finish = form.finish.value;
				// body.reply = form.reply.value;
				// body.replier = form.replier.value;
				
				body.content = form.content.value;
				
				// alert($.toJSON(body));
					
				$(this).dialog("close");
	
				$.post('emp.php?do=BusinessMy.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},

	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var a1 = ['编辑信息', 'url', 'BusinessMy.dialog_edit_', '650x400'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '650x400'];
		var a3 = ['复制信息', 'url', 'BusinessMy.dialog_copy_', '650x400'];
		
		var c1 = 'emp.php?do=BusinessMy.edit&id=' + id;
		var c2 = 'emp.php?do=BusinessMy.view&id=' + id;
		var c3 = 'emp.php?do=BusinessMy.copy&id=' + id;
		
		var c4 = 'emp.php?do=BusinessMy.upload&id=' + id;
		var a4 = ['上传附件', 'url', 'Common.dialog_upload', '600x420'];
		
		// 审核
		if (status == '1') {
			var d1 = 'emp.php?do=BusinessMy.verify&id=' + id;
			var b1 = ['审核信息', 'url', 'BusinessMy.dialog_verify', '650x400'];
			
			var s = d1 + ", " + c1 + ", " + c2 + ", " + c4;

			return popup(e, [b1, a1, a2, a4], s);
		}
		
		var d2 = 'emp.php?do=BusinessMy.finish&id=' + id;
		var b2 = ['完成处理', 'url', 'BusinessMy.dialog_finish', '650x400'];
		
		// 等待
		if (status == '2') {
			var d1 = 'emp.php?do=BusinessMy.verify&id=' + id;
			var b1 = ['开始处理', 'url', 'BusinessMy.dialog_begin', '650x400'];
			
			var s = d1 + ", " + d2 + ", " + c1 + ", " + c2 + ", " + c4;

			return popup(e, [b1, b2, a1, a2, a4], s);
		}
		
		// 正在
		if (status == '3') {
			
			var s = d2 + ", " + c1 + ", " + c2 + ", " + c4;

			return popup(e, [b2, a1, a2, a4], s);
		}
		
		// 完成
		if (status == '4') {
			var d3 = 'emp.php?do=BusinessMy.evaluation&id=' + id;
			var b3 = ['给予评价', 'url', 'BusinessMy.dialog_evaluation', '650x400'];
			
			var s = d3 + ", " + c1 + ", " + c2 + ", " + c4;

			return popup(e, [b3, a1, a2, a4], s);
		}
		
		var s = c2 + ", " + c3 + ", " + c4;

		popup(e, [a2, a3, a4], s);
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=BusinessMy.ajax_oper', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_edit")[0];
			
						var body = {};
						body.id = form.id.value;
						body.emp = form.emp.value;
						body.date = form.date.value;
						body.expect = form.expect.value;
						body.type = form.type.value;
						body.name = form.name.value;
						body.opinion1 = form.opinion1.value;
						body.opinion2 = form.opinion2.value;
						
						body.content = form.content.value;
			
						$(this).dialog("close");
			
						var url = 'emp.php?do=BusinessMy.editPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
			
						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});
			
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"复制": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
	
				var body = {};
				body.id = form.id.value;
				body.emp = form.emp.value;
				body.date = form.date.value;
				body.expect = form.expect.value;
				body.type = form.type.value;
				body.name = form.name.value;
				body.opinion1 = form.opinion1.value;
				body.opinion2 = form.opinion2.value;
				
				body.content = form.content.value;
	
				$(this).dialog("close");
	
				var url = 'emp.php?do=BusinessMy.addPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	dialog_verify: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}				

				var form = $("#form_edit")[0];
				
				var body = {};
				body.id = form.id.value;
				body.content = form.content.value;
				body.status = 2;
				
				$(this).dialog("close");

				var url = 'emp.php?do=BusinessMy.verifyPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},
	
	dialog_begin: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=BusinessMy.ajax_replier', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},
					
					"开始": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}				
		
						var form = $("#form_edit")[0];
						
						var body = {};
						body.id = form.id.value;
						body.content = form.content.value;
						body.status = 3;
						
						$(this).dialog("close");
		
						var url = 'emp.php?do=BusinessMy.verifyPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
		
						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});
		
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_finish: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=BusinessMy.ajax_replier', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},
					
					"完成": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}				
		
						var form = $("#form_edit")[0];
						
						var body = {};
						body.id = form.id.value;
						body.finish = form.finish.value;
						body.reply = form.reply.value;
						body.content = form.content.value;
						
						body.status = 4;
						
						$(this).dialog("close");
		
						var url = 'emp.php?do=BusinessMy.finishPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
		
						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});
		
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_evaluation: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=BusinessMy.ajax_emp', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},
					
					"提交" : function() {					
						if (!confirm("确认是否提交？")) {
							return false;
						}				
	
						var form = $("#form_edit")[0];
						
						var body = {};
						body.id = form.id.value;
						body.evaluation = form.evaluation.value;
						body.email = form.email.value;
						body.content = form.content.value;
						body.status = 5;
						
						$(this).dialog("close");
						
						var url = 'emp.php?do=BusinessMy.evaluationPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
	
						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});
	
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	}
	
};
